package br.unesp.ibb.lbbc.fba;

import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
import javax.xml.stream.XMLStreamException;

import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.Species;

public class ProgressBar extends JPanel implements PropertyChangeListener {

	private JProgressBar progressBar;
	public static JFrame frame;
	private StoichometryTask task;
	
	

	public ProgressBar() {
		super(new BorderLayout());

		progressBar = new JProgressBar(0, 100);
		progressBar.setValue(0);
		progressBar.setStringPainted(true);

		JPanel panel = new JPanel();
		//panel.add(startButton);
		panel.add(progressBar);

		add(panel, BorderLayout.PAGE_START);
		setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
		
		task = new StoichometryTask();
		task.addPropertyChangeListener(this);
		task.execute();
		
	}

	

	/**
	 * Invoked when task's progress property changes.
	 */
	public void propertyChange(PropertyChangeEvent evt) {
		if ("progress" == evt.getPropertyName()) {
			int progress = (Integer) evt.getNewValue();
			progressBar.setValue(progress);
		}
	}

	
	/**
	 * Create the GUI and show it. As with all GUI code, this must run on the
	 * event-dispatching thread.
	 */
	public void start() {
		// Create and set up the window.
		frame = new JFrame("Loading SBML file");
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Create and set up the content pane.
		JComponent stoi = new ProgressBar();
		stoi.setOpaque(true); // content panes must be opaque
		frame.setContentPane(stoi);
		
		// Display the window.
		frame.pack();
		frame.setVisible(true);
		
		
		
	}
	
	
public SwingWorker<double[][], Void> getTask(){
	return task;
}
 	
}



